package com.infodms.dms.actions.sysmng.dealer;

import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.infodms.dms.actions.common.FileUploadManager;
import com.infodms.dms.bean.AclUserBean;
import com.infodms.dms.common.Constant;
import com.infodms.dms.common.ErrorCodeConstant;
import com.infodms.dms.common.Utility;
import com.infodms.dms.dao.feedbackMng.StandardVipApplyManagerDao;
import com.infodms.dms.dao.productmanage.ProductManageDao;
import com.infodms.dms.dao.sales.dealer.DealerInfoDao;
import com.infodms.dms.exception.BizException;
import com.infodms.dms.po.FsFileuploadPO;
import com.infodms.dms.po.TcUserPO;
import com.infodms.dms.po.TmAuthDealerChangePO;
import com.infodms.dms.po.TmCompanyPO;
import com.infodms.dms.po.TmDealerBusinessAreaPO;
import com.infodms.dms.po.TmDealerChangePO;
import com.infodms.dms.po.TmDealerOrgRelationPO;
import com.infodms.dms.po.TmDealerPO;
import com.infodms.dms.po.TmDealerPriceRelationPO;
import com.infodms.dms.po.TmOrgPO;
import com.infodms.dms.po.TmVsAddressPO;
import com.infodms.dms.po.TtAsDealerTypePO;
import com.infodms.dms.po.TtVsPricePO;
import com.infodms.dms.util.CommonUtils;
import com.infodms.dms.util.StringUtil;
import com.infodms.dms.util.sequenceUitl.SequenceManager;
import com.infoservice.mvc.context.ActionContext;
import com.infoservice.mvc.context.RequestWrapper;
import com.infoservice.po3.POFactory;
import com.infoservice.po3.POFactoryBuilder;
import com.infoservice.po3.bean.PageResult;

/**
 * @Title: CHANADMS
 *
 * @Description:
 *
 * @Copyright: Copyright (c) 2010
 *
 * @Company:  www.infoservice.com.cn
 * @Date: 2010-7-5
 *
 * @author zjy 
 * @mail   zhaojinyu@infoservice.com.cn
 * @version 1.0
 * @remark 
 */
public class DealerInfo {
	public Logger logger = Logger.getLogger(DealerInfo.class);
	private final String queryDealerInitUrl = "/jsp/systemMng/dealer/dealerInfo.jsp";
	private final String queryDealerInitDetailUrl="/jsp/systemMng/dealer/dealerInfoDetail.jsp";
	private final String addNewDealerUrl="/jsp/systemMng/dealer/addNewDealer.jsp";
	private final String addBusinessUrl="/jsp/systemMng/dealer/addBusiness.jsp";
	private final String addAddressUrl="/jsp/systemMng/dealer/addAddress.jsp";
	private final String modifyAddressUrl="/jsp/systemMng/dealer/modifyAddress.jsp";
	private final String getPriceUrl="/jsp/systemMng/dealer/getPrice.jsp";
	private final String getMyPriceUtl="/jsp/systemMng/dealer/myPrice.jsp";
	private final String BALANCE_STOP_URL = "/jsp/systemMng/dealer/balanceStopInit.jsp" ;
	private final String BALANCE_STOP_UPDATE = "/jsp/systemMng/dealer/balanceStopUpdate.jsp" ;
	
	private final String dealerInfoChangeInitUrl = "/jsp/systemMng/dealer/dealerInfoChangeInit.jsp";
	private final String addDealerInfoChangeUrl = "/jsp/systemMng/dealer/addDealerInfoChange.jsp";
	private final String dealerDetailInfo = "/jsp/systemMng/dealer/dealerDetailInfo.jsp";
	private final String updateDealerDetailInfo = "/jsp/systemMng/dealer/updateDealerDetailInfo.jsp";
	
	private final String authDealerChangeInitUrl = "/jsp/systemMng/dealer/authDealerChangeInit.jsp";
	private final String authDetailInfo = "/jsp/systemMng/dealer/authDetailInfo.jsp";
	private final String dealerChangeInfo = "/jsp/systemMng/dealer/dealerChangeInfo.jsp";
	/**
	 * 经销商维护查询页面初始化
	 * @param null
	 * @return void
	 * @throws Exception
	 */
public void queryDealerInfoInit() {
	ActionContext act = ActionContext.getContext();
	AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
	try {
			act.setForword(queryDealerInitUrl);
		} catch (Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"经销商维护pre查询");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
/**
 * 经销商维护新增页面
 * @param null
 * @return void
 * @throws Exception
 */
public void addNewDealer() {
	ActionContext act = ActionContext.getContext();
	AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
	try {
			ProductManageDao dao = new ProductManageDao();
			List<Map<String, Object>> types = dao.getPriceTypeList(logonUser
				.getCompanyId());
			act.setOutData("types", types);
			act.setForword(addNewDealerUrl);
		} catch (Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"经销商维护新增");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
/**
 * 经销商维护查询结果页面
 * @param null
 * @return void
 * @throws Exception
 */
public void queryDealerInfo(){
	ActionContext act = ActionContext.getContext();
	AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
	try {
		RequestWrapper request = act.getRequest();
		String dealerCode = request.getParamValue("DEALER_CODE");
		String dealerName = request.getParamValue("DEALER_NAME");
		String dealerLevel = request.getParamValue("DEALERLEVEL");
		String status = request.getParamValue("DEALERSTATUS");
		String sJdealerCode = request.getParamValue("sJDealerCode");
		String orgCode = request.getParamValue("orgCode");
		String dealerType = request.getParamValue("DEALERTYPE");
		String dealerClass=request.getParamValue("DEALERCLASS");
		String province = request.getParamValue("province");
		// 经销商ID
		String companyId = request.getParamValue("COMPANY_ID");
		String oemCompanyId = logonUser.getCompanyId().toString();
		DealerInfoDao dao=new DealerInfoDao();
		Integer curPage = request.getParamValue("curPage") != null ? Integer.parseInt(request.getParamValue("curPage"))
				: 1; // 处理当前页
				//Constant.PAGE_SIZE, curPage
		PageResult<Map<String, Object>> ps = dao.queryDealerInfo(dealerClass,dealerCode, dealerName,dealerLevel,status,sJdealerCode,orgCode,dealerType,companyId,oemCompanyId,province,curPage,Constant.PAGE_SIZE);  
		act.setOutData("ps", ps);
		act.setForword(queryDealerInitUrl);
	} catch (Exception e) {
		BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"经销商维护查询结果");
		logger.error(logonUser,e1);
		act.setException(e1);
	}
}
/**
 * 经销商维护修改页面
 * @param null
 * @return void
 * @throws Exception
 */
public void queryDealerInfoDetail(){
	ActionContext act = ActionContext.getContext();
	AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
	try {
		RequestWrapper request = act.getRequest();
		String dealerId = request.getParamValue("DEALER_ID");
		DealerInfoDao dao=new DealerInfoDao();
		ProductManageDao productDao = new ProductManageDao();
		List<Map<String, Object>> types = productDao.getmyPriceTypeList(logonUser.getCompanyId(),dealerId);
			Map map=productDao.getMyMap(logonUser.getCompanyId(), dealerId);
			types.add(map);
			act.setOutData("types", types);
		queryMonth(act, dao, dealerId, queryDealerInitDetailUrl);
	} catch (Exception e) {
		BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"经销商维护修改");
		logger.error(logonUser,e1);
		act.setException(e1);
	}
}
/**
 * 经销商修改维护
 * @param null
 * @return void
 * @throws Exception
 */
public void modifyDealerPrice(){
	ActionContext act=ActionContext.getContext();
	AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
	try {
	RequestWrapper request = act.getRequest();
	String erpCode= request.getParamValue("erpCode");
	DealerInfoDao dao=new DealerInfoDao();
	dao.setDownDealerPrice(erpCode);
	queryDealerInfoInit();
	}catch (Exception e) {
		BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"经销商修改维护");
		logger.error(logonUser,e1);
		act.setException(e1);
	}
}

/**
 * 经销商维护保存
 * @param null
 * @return void
 * @throws Exception
 */
public void saveDealerInfo(){
	ActionContext act = ActionContext.getContext();
	AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
	try {
		RequestWrapper request = act.getRequest();
		//CommonUtils.checkNull() 校验是否为空
		String dealerCode = CommonUtils.checkNull(request.getParamValue("DEALER_CODE"));//经销商代码
		String dealerName = CommonUtils.checkNull(request.getParamValue("DEALER_NAME"));//经销商名称
		String shortName = CommonUtils.checkNull(request.getParamValue("SHORT_NAME"));//简称
		String dealerLevel = CommonUtils.checkNull(request.getParamValue("DEALERLEVEL"));//经销商等级
		String orgId = CommonUtils.checkNull(request.getParamValue("orgId"));//上级组织ID
		String sJDealerId = CommonUtils.checkNull(request.getParamValue("sJDealerId"));//上级经销商ID
		String dealerType = CommonUtils.checkNull(request.getParamValue("DEALERTYPE"));//经销商类型
		String companyId = CommonUtils.checkNull(request.getParamValue("COMPANY_ID"));//经销商公司ID
		String provinceId = CommonUtils.checkNull(request.getParamValue("province"));//省
		String cityId = CommonUtils.checkNull(request.getParamValue("city"));//市
		String zipCode = CommonUtils.checkNull(request.getParamValue("zipCode"));//邮编
		String linkMan = CommonUtils.checkNull(request.getParamValue("linkMan"));//联系人
		String phone = CommonUtils.checkNull(request.getParamValue("phone"));//电话
		String faxNo = CommonUtils.checkNull(request.getParamValue("faxNo"));//传真
		String email = CommonUtils.checkNull(request.getParamValue("email"));//邮箱
		String address = CommonUtils.checkNull(request.getParamValue("address"));//详细地址
		String remark = CommonUtils.checkNull(request.getParamValue("remark"));//备注
		String status = CommonUtils.checkNull(request.getParamValue("DEALERSTATUS"));//经销商状态
		String dealerClass=CommonUtils.checkNull(request.getParamValue("DEALERCLASS"));//经销商级别
		// String priceId = CommonUtils.checkNull(request.getParamValue("priceId"));//价格ID
		String erpCode=CommonUtils.checkNull(request.getParamValue("erpCode"));//开票单位
		String taxesNo = CommonUtils.checkNull(request.getParamValue("taxesNo"));//税号
		String labourType = CommonUtils.checkNull(request.getParamValue("DEALER_LABOUR_CODE"));//经销商作业等级
		String isDqv = CommonUtils.checkNull(request.getParamValue("IS_DQV"));//是否为DQV
		
		/***********add by liuxh 20101116增加结算级别和开票级别维护**************/
		String balanceLevel = CommonUtils.checkNull(request.getParamValue("BALANCE_LEVEL"));//结算等级别
		String invoiceLevel = CommonUtils.checkNull(request.getParamValue("INVOICE_LEVEL"));//开票级别
		/***********add by liuxh 20101116增加结算级别和开票级别维护**************/
		
		
		/***********add by zhumingwei 2011-02-22**************/
		String COUNTIES = CommonUtils.checkNull(request.getParamValue("COUNTIES"));//区/县
		String TOWNSHIP = CommonUtils.checkNull(request.getParamValue("TOWNSHIP"));//乡
		String LEGAL = CommonUtils.checkNull(request.getParamValue("LEGAL"));//法人
		String WEBMASTER_PHONE = CommonUtils.checkNull(request.getParamValue("WEBMASTER_PHONE"));//站长电话
		String DUTY_PHONE = CommonUtils.checkNull(request.getParamValue("DUTY_PHONE"));//值班电话
		String BANK = CommonUtils.checkNull(request.getParamValue("BANK"));//开户行
		String MAIN_RESOURCES = CommonUtils.checkNull(request.getParamValue("MAIN_RESOURCES"));//维修资源
		String ADMIN_LEVEL = CommonUtils.checkNull(request.getParamValue("ADMIN_LEVEL"));//行政级别
		String IMAGE_LEVEL = CommonUtils.checkNull(request.getParamValue("IMAGE_LEVEL"));//形象等级
		//String TAX_LEVEL = CommonUtils.checkNull(request.getParamValue("TAX_LEVEL"));//纳税级别
		/***********add by zhumingwei 2011-02-22**************/
		
		//经销商评级 没有
		
		//校验新维护的经销商是否存在 开始
		
		//结束
		//插入新的经销商开始
		//生成dealerId
		String dealerId=SequenceManager.getSequence("");
		//session中取到经销商的车厂公司ID和用户ID
		Long oemCompanyId=logonUser.getCompanyId();
		Long userId =logonUser.getUserId();
		Date currTime = new Date(System.currentTimeMillis());
		//实例化dao层
		DealerInfoDao dao=new DealerInfoDao();
		List<TmOrgPO> list=dao.getOrgInfo(new Long(companyId));
		TmOrgPO tmo=new TmOrgPO();
		if(list.size()>0)
		{
			tmo=(TmOrgPO)list.get(0);	
		}
		TmDealerPO po=new TmDealerPO();
		po.setDealerId(new Long(dealerId));
		po.setDealerCode(dealerCode);
		
		po.setBalanceLevel(balanceLevel);
		po.setInvoiceLevel(invoiceLevel);
		
		po.setDealerName(dealerName);
		po.setDealerShortname(shortName);
		po.setCompanyId(new Long(companyId));
		po.setAddress(address);
		po.setErpCode(erpCode);
		if(labourType!=null&&!labourType.equals("")){
		po.setDealerLabourType(Integer.valueOf(labourType));
		}
		else{
			po.setDealerLabourType(Integer.valueOf(0));
		}
		if (!"".equals(taxesNo)) {
			po.setTaxesNo(taxesNo.trim());
		}
		if(!"".equals(cityId))
		{
			po.setCityId(new Long(cityId));	
		}
		if(!"".equals(provinceId))
		{
		po.setProvinceId(new Long(provinceId));
		}
		po.setCreateBy(userId);
		po.setCreateDate(currTime);
		po.setDealerLevel(new Integer(dealerLevel));
		po.setDealerOrgId(tmo.getOrgId());
		po.setDealerType(new Integer(dealerType));
		/***********add by zhumingwei 2011-02-22**************/
		if(!"".equals(COUNTIES)){
			po.setCounties(Integer.parseInt(COUNTIES));
		}
		po.setTownship(TOWNSHIP);
		po.setLegal(LEGAL);
		po.setWebmasterPhone(WEBMASTER_PHONE);
		po.setDutyPhone(DUTY_PHONE);
		po.setBank(BANK);
		//po.setTaxLevel(TAX_LEVEL);//暂时还未用到
		if(!"".equals(MAIN_RESOURCES)){
			po.setMainResources(Integer.parseInt(MAIN_RESOURCES));
		}
		if(!"".equals(IMAGE_LEVEL)){
			po.setImageLevel(Integer.parseInt(IMAGE_LEVEL));
		}
		po.setImageDate(new Date());
		if(!"".equals(ADMIN_LEVEL)){
			po.setAdminLevel(Integer.parseInt(ADMIN_LEVEL));
		}
		/***********add by zhumingwei 2011-02-22**************/
		
		if(String.valueOf(Constant.DEALER_LEVEL_01).equals(dealerLevel))
		{
	        po.setParentDealerD(new Long(-1));
		}else
		{
			po.setParentDealerD(new Long(sJDealerId));
		}
		if(dealerClass!=null&&dealerClass!=""){
		po.setDealerClass(Integer.parseInt(dealerClass));
		}
		po.setEmail(email);
		po.setFaxNo(faxNo);
		po.setLinkMan(linkMan);
		po.setOemCompanyId(oemCompanyId);
		po.setPhone(phone);
		po.setRemark(remark);
		po.setStatus(new Integer(status));
		po.setZipCode(zipCode);
		po.setIsDqv(Integer.parseInt(isDqv));
		/*if(!"".equals(priceId)){
			po.setPriceId(new Long(priceId));
		}*/
		dao.insert(po);
		if(String.valueOf(Constant.DEALER_LEVEL_01).equals(dealerLevel))
		{
			String relationId=SequenceManager.getSequence("");
			TmDealerOrgRelationPO tdor=new 	TmDealerOrgRelationPO();
			tdor.setRelationId(new Long(relationId));
			tdor.setBusinessType(Constant.ORG_TYPE_OEM);
			tdor.setOrgId(new Long(orgId));
			tdor.setDealerId(new Long(dealerId));
			tdor.setCreateBy(userId);
			tdor.setCreateDate(currTime);
			dao.insert(tdor);
		}
		//结束
		//生成经销商对应的账户信息 开始
		
		//结束
		ProductManageDao productDao = new ProductManageDao();
		List<Map<String, Object>> types = productDao.getmyPriceTypeList(logonUser
				.getCompanyId(),dealerId);
			act.setOutData("types", types);
		queryMonth(act, dao, dealerId, queryDealerInitDetailUrl);
	} catch (Exception e) {
		BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"经销商维护新增");
		logger.error(logonUser,e1);
		act.setException(e1);
	}
}
/**
 * 经销商维护修改
 * @param null
 * @return void
 * @throws Exception
 */
public void modifyDealerInfo(){
	ActionContext act = ActionContext.getContext();
	AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
	try {
		
		Date newdate=new Date();
		SimpleDateFormat newformat=new SimpleDateFormat("yyyy-MM-dd");
		RequestWrapper request = act.getRequest();
		//CommonUtils.checkNull() 校验是否为空
		String dealerCode = CommonUtils.checkNull(request.getParamValue("DEALER_CODE"));//经销商代码
		String dealerName = CommonUtils.checkNull(request.getParamValue("DEALER_NAME"));//经销商名称
		String shortName = CommonUtils.checkNull(request.getParamValue("SHORT_NAME"));//简称
		String dealerLevel = CommonUtils.checkNull(request.getParamValue("DEALERLEVEL"));//经销商等级
		String orgId = CommonUtils.checkNull(request.getParamValue("orgId"));//上级组织ID
		String sJDealerId = CommonUtils.checkNull(request.getParamValue("sJDealerId"));//上级经销商ID
		String dealerType = CommonUtils.checkNull(request.getParamValue("DEALERTYPE"));//经销商类型
		String companyId = CommonUtils.checkNull(request.getParamValue("COMPANY_ID"));//经销商公司ID
		String provinceId = CommonUtils.checkNull(request.getParamValue("province"));//省
		String cityId = CommonUtils.checkNull(request.getParamValue("city"));//市
		String zipCode = CommonUtils.checkNull(request.getParamValue("zipCode"));//邮编
		String linkMan = CommonUtils.checkNull(request.getParamValue("linkMan"));//联系人
		String phone = CommonUtils.checkNull(request.getParamValue("phone"));//电话
		String faxNo = CommonUtils.checkNull(request.getParamValue("faxNo"));//传真
		String email = CommonUtils.checkNull(request.getParamValue("email"));//邮箱
		String address = CommonUtils.checkNull(request.getParamValue("address"));//详细地址
		String remark = CommonUtils.checkNull(request.getParamValue("remark"));//备注
		String status = CommonUtils.checkNull(request.getParamValue("DEALERSTATUS"));//经销商状态
		String dealerId=CommonUtils.checkNull(request.getParamValue("DEALER_ID"));//经销商Id
		String dealerClass=CommonUtils.checkNull(request.getParamValue("DEALERCLASS"));
		//String priceId=CommonUtils.checkNull(request.getParamValue("priceId"));//价格Id
		String erpCode=CommonUtils.checkNull(request.getParamValue("erpCode"));//开票单位
		String taxesNo = CommonUtils.checkNull(request.getParamValue("taxesNo"));//税号
		String labourType = CommonUtils.checkNull(request.getParamValue("DEALER_LABOUR_CODE"));//经销商作业等级
		String isDqv = CommonUtils.checkNull(request.getParamValue("IS_DQV"));//是否为DQV
		
		/***********add by liuxh 20101116增加结算级别和开票级别维护**************/
		String balanceLevel = CommonUtils.checkNull(request.getParamValue("BALANCE_LEVEL"));//结算等级别
		String invoiceLevel = CommonUtils.checkNull(request.getParamValue("INVOICE_LEVEL"));//开票级别
		/***********add by liuxh 20101116增加结算级别和开票级别维护**************/
		
		/***********add by zhumingwei 2011-02-22**************/
		String COUNTIES = CommonUtils.checkNull(request.getParamValue("COUNTIES"));//区/县
		String TOWNSHIP = CommonUtils.checkNull(request.getParamValue("TOWNSHIP"));//乡
		String LEGAL = CommonUtils.checkNull(request.getParamValue("LEGAL"));//法人
		String WEBMASTER_PHONE = CommonUtils.checkNull(request.getParamValue("WEBMASTER_PHONE"));//站长电话
		String DUTY_PHONE = CommonUtils.checkNull(request.getParamValue("DUTY_PHONE"));//值班电话
		String BANK = CommonUtils.checkNull(request.getParamValue("BANK"));//开户行
		String MAIN_RESOURCES = CommonUtils.checkNull(request.getParamValue("MAIN_RESOURCES"));//维修资源
		String ADMIN_LEVEL = CommonUtils.checkNull(request.getParamValue("ADMIN_LEVEL"));//行政级别
		String IMAGE_LEVEL = CommonUtils.checkNull(request.getParamValue("IMAGE_LEVEL"));//形象等级
		//String TAX_LEVEL = CommonUtils.checkNull(request.getParamValue("TAX_LEVEL"));//纳税级别
		/***********add by zhumingwei 2011-02-22**************/
		
		//经销商评级 没有
		
		//校验新维护的经销商是否存在 开始
		
		//结束
		//插入新的经销商开始
		//生成dealerId
		//session中取到经销商的车厂公司ID和用户ID
		Long oemCompanyId=logonUser.getCompanyId();
		Long userId =logonUser.getUserId();
		//Date currTime = new Date(System.currentTimeMillis());
		Date currTime=newformat.parse(newformat.format(newdate));
		//实例化dao层
		DealerInfoDao dao=new DealerInfoDao();
		Map<String, Object> map=dao.getDealerInfobyId(dealerId);
		String yuanDealerLevel=String.valueOf(map.get("DEALER_LEVEL"));
		List<TmOrgPO> list=dao.getOrgInfo(new Long(companyId));
//		TcUserPO tcUser1=new TcUserPO();
//		tcUser1.setUserId(userId);
//		TcUserPO tcUser2=new TcUserPO();
//		tcUser2.setUpdateDate(currTime);
//		dao.update(tcUser1,tcUser2);
		TmOrgPO tmo=new TmOrgPO();
		if(list.size()>0)
		{
			tmo=(TmOrgPO)list.get(0);	
		}
		TmDealerPO po=new TmDealerPO();
		TmDealerPO conntionPO=new TmDealerPO();
		conntionPO.setDealerId(new Long(dealerId));
		
		po.setBalanceLevel(balanceLevel);
		po.setInvoiceLevel(invoiceLevel);
		
		po.setDealerCode(dealerCode);
		po.setDealerName(dealerName);
		po.setDealerShortname(shortName);
		po.setCompanyId(new Long(companyId));
		po.setAddress(address);
		po.setErpCode(erpCode);
		if(labourType!=null&&!labourType.equals("")){
			po.setDealerLabourType(Integer.valueOf(labourType));
		}
		else{
			po.setDealerLabourType(Integer.valueOf(0));
		}
		if (!"".equals(taxesNo)) {
			po.setTaxesNo(taxesNo.trim());
		}
		if(!"".equals(cityId))
		{
			po.setCityId(new Long(cityId));	
		}
		if(!"".equals(provinceId))
		{
		po.setProvinceId(new Long(provinceId));
		}
		//po.setCreateBy(userId);
		//po.setCreateDate(currTime);
		po.setUpdateBy(userId);
		po.setUpdateDate(currTime);
		po.setDealerLevel(new Integer(dealerLevel));
		po.setDealerOrgId(tmo.getOrgId());
		po.setDealerType(new Integer(dealerType));
		
		/***********add by zhumingwei 2011-02-22**************/
		if(!"".equals(COUNTIES)){
			po.setCounties(Integer.parseInt(COUNTIES));
		}
		po.setTownship(TOWNSHIP);
		po.setLegal(LEGAL);
		po.setWebmasterPhone(WEBMASTER_PHONE);
		po.setDutyPhone(DUTY_PHONE);
		po.setBank(BANK);
		//po.setTaxLevel(TAX_LEVEL);//暂时还未用到
		if(!"".equals(MAIN_RESOURCES)){
			po.setMainResources(Integer.parseInt(MAIN_RESOURCES));
		}
		if(!"".equals(IMAGE_LEVEL)){
			po.setImageLevel(Integer.parseInt(IMAGE_LEVEL));
		}
		po.setChangeDate(new Date());
		if(!"".equals(ADMIN_LEVEL)){
			po.setAdminLevel(Integer.parseInt(ADMIN_LEVEL));
		}
		/***********add by zhumingwei 2011-02-22**************/
		
		if(String.valueOf(Constant.DEALER_LEVEL_01).equals(dealerLevel))
		{
	        po.setParentDealerD(new Long(-1));
		}else
		{
			po.setParentDealerD(new Long(sJDealerId));
		}
		if(dealerClass!=null&&dealerClass!=""){
			po.setDealerClass(Integer.parseInt(dealerClass));
		}
		po.setEmail(email);
		po.setFaxNo(faxNo);
		po.setLinkMan(linkMan);
		po.setOemCompanyId(oemCompanyId);
		po.setPhone(phone);
		po.setRemark(remark);
		po.setStatus(new Integer(status));
		po.setZipCode(zipCode);
		po.setIsDqv(Integer.parseInt(isDqv));
		//if(!"".equals(priceId)){
			//po.setPriceId(new Long(priceId));
		//}
		dao.update(conntionPO, po);
		if(String.valueOf(Constant.DEALER_LEVEL_01).equals(yuanDealerLevel))//如果修改之前也是一级经销商则先删除原来与组织的对应关系
		{
			TmDealerOrgRelationPO tdor=new 	TmDealerOrgRelationPO();
			tdor.setDealerId(new Long(dealerId));
			dao.delete(tdor);
		}
		if(String.valueOf(Constant.DEALER_LEVEL_01).equals(dealerLevel))//修改为一级时插入与车厂组织的对应关系
		{
			String relationId=SequenceManager.getSequence("");
			TmDealerOrgRelationPO tdor=new 	TmDealerOrgRelationPO();
			tdor.setRelationId(new Long(relationId));
			tdor.setOrgId(new Long(orgId));
			tdor.setDealerId(new Long(dealerId));
			tdor.setCreateBy(userId);
			tdor.setCreateDate(currTime);
			dao.insert(tdor);
		}
		
		//结束
		act.setForword(queryDealerInitUrl);
	} catch (Exception e) {
		BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"经销商维护新增");
		logger.error(logonUser,e1);
		act.setException(e1);
	}
}
public void addBusiness()
{
	ActionContext act = ActionContext.getContext();
	AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
	try {
		RequestWrapper request = act.getRequest();
		//CommonUtils.checkNull() 校验是否为空
		String dealerId = CommonUtils.checkNull(request.getParamValue("dealerId"));//经销商ID
		//从session中查询公司ID
		Long companyId=logonUser.getCompanyId();
		DealerInfoDao dao=new DealerInfoDao();
		//查询经销商业务范围信息
		List<Map<String, Object>> businessList=dao.getBusinessNoInDealer(dealerId,companyId);
		act.setOutData("businessList", businessList);
		act.setOutData("dealerId", dealerId);
		act.setForword(addBusinessUrl);
	} catch (Exception e) {
		BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"经销商维护新增");
		logger.error(logonUser,e1);
		act.setException(e1);
	}
}
public void saveBusiness()
{
	ActionContext act = ActionContext.getContext();
	AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
	try {
			RequestWrapper request = act.getRequest();
			//CommonUtils.checkNull() 校验是否为空
			String dealerId = CommonUtils.checkNull(request.getParamValue("DEALER_ID"));//经销商ID
			String areaIds = CommonUtils.checkNull(request.getParamValue("areaId"));//多个业务范围ID以","分割
			//从session中查询公司ID
			Date currTime = new Date(System.currentTimeMillis());
			Long userId=logonUser.getUserId();
			DealerInfoDao dao=new DealerInfoDao();
			if(!"".equals(areaIds))
			{
				String[]  s=areaIds.split(",");
				for(int i=0;i<s.length;i++)
				{
					String areaId=s[i];
					String relationId=SequenceManager.getSequence("");
					TmDealerBusinessAreaPO po=new TmDealerBusinessAreaPO();
					po.setAreaId(Long.valueOf(areaId));
					po.setCreateBy(userId);
					po.setCreateDate(currTime);
					po.setDealerId(Long.valueOf(dealerId));
					po.setRelationId(Long.valueOf(relationId));
					dao.insert(po);
				}
			}
			//queryMonth(act, dao, dealerId, queryDealerInitDetailUrl);	
			act.setOutData("returnValue", 1);
		
	} catch (Exception e) {
		BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"经销商维护新增");
		logger.error(logonUser,e1);
		act.setException(e1);
	}	
}
	public void defaultMyPriceView(){
		ActionContext act = ActionContext.getContext();
		RequestWrapper request = act.getRequest();
		act.setOutData("priceId", request.getParamValue("priceId"));
		act.setOutData("relationId", request.getParamValue("relationId"));
		act.setOutData("dealerId", request.getParamValue("dealerId"));
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		act.setForword(getMyPriceUtl);
}
/*
 * 设置默认价格价格
 */
public void defaultPrice(){
	ActionContext act = ActionContext.getContext();
	AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
	try{
	DealerInfoDao dao=new DealerInfoDao();
	RequestWrapper request = act.getRequest();
	String startDate=request.getParamValue("startDate");//开始和结束日期
	String endDate=request.getParamValue("endDate");
	String priceId=request.getParamValue("priceId");
	TtVsPricePO ttVsPricePo1=new TtVsPricePO();
	ttVsPricePo1.setPriceId(Long.parseLong(priceId));
	TtVsPricePO ttVsPricePo2=new TtVsPricePO();
	ttVsPricePo2.setStartDate(CommonUtils.parseDate(startDate));//修改开始和结束日期
	ttVsPricePo2.setEndDate(CommonUtils.parseDate(endDate));
	dao.update(ttVsPricePo1, ttVsPricePo2);
	String DEALERSTATUS=request.getParamValue("DEALERSTATUS");
	String dealerId = CommonUtils.checkNull(request.getParamValue("DEALER_ID"));//经销商ID
	//String relationId=request.getParamValue("relationId");
	String relationId = CommonUtils.checkNull(request.getParamValue("relationId"));//经销商与默认价格关系表主键
	TmDealerPriceRelationPO po5=new TmDealerPriceRelationPO();
	po5.setRelationId(Long.parseLong(relationId));
	po5.setIsDefault(Constant.IF_TYPE_YES);
	
	if(DEALERSTATUS.equals((Constant.IF_TYPE_NO).toString())&&dao.select(po5).size()>0){
		act.setOutData("returnValue","2");
	}else{
		TmDealerPriceRelationPO po1=new TmDealerPriceRelationPO();
		po1.setDealerId(Long.parseLong(dealerId));
		TmDealerPriceRelationPO po2=new TmDealerPriceRelationPO();
		po2.setIsDefault(Constant.IF_TYPE_NO);//把该经销商下所有的价格都设置成不是默认的
		dao.update(po1, po2);
		TmDealerPriceRelationPO po3=new TmDealerPriceRelationPO();
		//DealerInfoDao dao=new DealerInfoDao();
		po3.setRelationId(Long.parseLong(relationId));
		TmDealerPriceRelationPO po4=new TmDealerPriceRelationPO();
		po4.setIsDefault(Constant.IF_TYPE_YES);//设置当前经销商是默认
		dao.update(po3, po4);
		
	}
	//dao.delete(po);
	ProductManageDao productDao = new ProductManageDao();
	List<Map<String, Object>> types = productDao.getmyPriceTypeList(logonUser.getCompanyId(),dealerId);
		act.setOutData("types", types);
	//queryMonth(act, dao, dealerId, queryDealerInitDetailUrl);
		Map<String, Object> map = dao.getDealerInfobyId(dealerId);
		// 查询经销商业务范围信息
		List<Map<String, Object>> businessList = dao
				.getDealerBusinessArea(dealerId);
		// 查询经销商地址信息
		List<Map<String, Object>> addressList = dao.getAddress(dealerId);
		act.setOutData("businessList", businessList);
		act.setOutData("addressList", addressList);
		act.setOutData("map", map);
} catch (Exception e) {
	BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"经销商价格有误！");
	logger.error(logonUser,e1);
	act.setException(e1);
}	
}
/*
 * 删除价格
 */
public void delPrice(){
	ActionContext act = ActionContext.getContext();
	AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
	try{
	
	RequestWrapper request = act.getRequest();
	String dealerId = CommonUtils.checkNull(request.getParamValue("DEALER_ID"));//经销商ID
	TmDealerPriceRelationPO po=new TmDealerPriceRelationPO();
	String relationId = CommonUtils.checkNull(request.getParamValue("relationId"));//经销商与默认价格关系表主键
	DealerInfoDao dao=new DealerInfoDao();
	po.setRelationId(Long.parseLong(relationId));
	dao.delete(po);
	ProductManageDao productDao = new ProductManageDao();
	List<Map<String, Object>> types = productDao.getmyPriceTypeList(logonUser.getCompanyId(),dealerId);
		act.setOutData("types", types);
	queryMonth(act, dao, dealerId, queryDealerInitDetailUrl);
} catch (Exception e) {
	BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"经销商价格有误！");
	logger.error(logonUser,e1);
	act.setException(e1);
}	
}

public void delBusiness()
{
	ActionContext act = ActionContext.getContext();
	AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
	try {
			RequestWrapper request = act.getRequest();
			//CommonUtils.checkNull() 校验是否为空
			String dealerId = CommonUtils.checkNull(request.getParamValue("DEALER_ID"));//经销商ID
			String relationId = CommonUtils.checkNull(request.getParamValue("relationId"));//经销商与业务范围关系表主键
			DealerInfoDao dao=new DealerInfoDao();		
			TmDealerBusinessAreaPO po=new TmDealerBusinessAreaPO();
			po.setRelationId(Long.valueOf(relationId));
			dao.delete(po);
			queryMonth(act, dao, dealerId, queryDealerInitDetailUrl);			
		
	} catch (Exception e) {
		BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"经销商维护新增");
		logger.error(logonUser,e1);
		act.setException(e1);
	}	
}
public void delAdd()
{
	ActionContext act = ActionContext.getContext();
	AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
	try {
			RequestWrapper request = act.getRequest();
			//CommonUtils.checkNull() 校验是否为空
			String dealerId = CommonUtils.checkNull(request.getParamValue("DEALER_ID"));//经销商ID
			String id = CommonUtils.checkNull(request.getParamValue("id"));//地址表主键
			DealerInfoDao dao=new DealerInfoDao();		
			TmVsAddressPO po=new TmVsAddressPO();
			po.setId(Long.valueOf(id));
			dao.delete(po);
			queryMonth(act, dao, dealerId, queryDealerInitDetailUrl);			
		
	} catch (Exception e) {
		BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"经销商维护新增");
		logger.error(logonUser,e1);
		act.setException(e1);
	}	
}
/*
 * 价格维护新增页面
 */
public void addPrice() {
	ActionContext act = ActionContext.getContext();
	AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
	try {
		RequestWrapper request = act.getRequest();
		String dealerId = CommonUtils.checkNull(request.getParamValue("dealerId"));//经销商ID
		act.setOutData("dealerId", dealerId);
//		ProductManageDao productDao = new ProductManageDao();
//		List<Map<String, Object>> mytypes = productDao.getmyOtherPriceTypeList(logonUser.getCompanyId(),dealerId);
//		act.setOutData("mytypes",mytypes);
		act.setForword(getPriceUrl);
		} catch (Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"经销商维护新增");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
public void addPrice_showPrice(){
	ActionContext act = ActionContext.getContext();
	AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
	try {
		RequestWrapper request = act.getRequest();
		String dealerId = CommonUtils.checkNull(request.getParamValue("DEALER_ID"));	//经销商ID
		String priceDesc = CommonUtils.checkNull(request.getParamValue("priceDesc"));	//价格类型描述
		//String defaultPrice = CommonUtils.checkNull(request.getParamValue("DEFAULTPRICE"));	//默认价格
		ProductManageDao productDao = new ProductManageDao();
		
		Integer curPage = request.getParamValue("curPage") != null ? Integer
				.parseInt(request.getParamValue("curPage"))
				: 1; // 处理当前页
		PageResult<Map<String, Object>> ps = productDao.getmyOtherPriceTypeList(priceDesc,logonUser.getCompanyId(),dealerId, curPage, Constant.PAGE_SIZE);
		act.setOutData("ps",ps);
		} catch (Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"经销商维护:新增价格");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
}

/**
 * 地址维护新增页面
 * @param null
 * @return void
 * @throws Exception
 */
public void addAddress() {
	ActionContext act = ActionContext.getContext();
	AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
	try {
		RequestWrapper request = act.getRequest();
		//CommonUtils.checkNull() 校验是否为空
		String dealerId = CommonUtils.checkNull(request.getParamValue("dealerId"));//经销商ID
		act.setOutData("dealerId", dealerId);	
		act.setForword(addAddressUrl);
		} catch (Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"经销商维护新增");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
/*
 * 添加经销商价格
 */
public void savePrice(){
	ActionContext act=ActionContext.getContext();
	AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
	Date currTime = new Date(System.currentTimeMillis());
	RequestWrapper request = act.getRequest();
	DealerInfoDao dao=new DealerInfoDao();
	TmDealerPriceRelationPO po=new TmDealerPriceRelationPO();
	String dealerId=CommonUtils.checkNull(request.getParamValue("DEALER_ID"));
	String defaultPrice= Constant.IF_TYPE_YES.toString();
	String defaultPriceN= Constant.IF_TYPE_NO.toString();
	String userPrice=CommonUtils.checkNull(request.getParamValue("priceId"));
	
//	TmDealerPriceRelationPO num1=new TmDealerPriceRelationPO();
//	num1.setDealerId(Long.parseLong(dealerId));
//	num1.setIsDefault(Integer.parseInt(defaultPriceN));
//	
//	TmDealerPriceRelationPO num2=new TmDealerPriceRelationPO();
//	num2.setDealerId(Long.parseLong(dealerId));
//	
//	dao.update(num2,num1);
	
	po.setCreateBy(logonUser.getUserId());
	po.setRelationId(new Long(SequenceManager.getSequence("")));
	po.setCreateDate(currTime);
	po.setDealerId(Long.parseLong(dealerId));
	po.setIsDefault(Integer.parseInt(defaultPriceN));
	po.setPriceId(Long.parseLong(userPrice));
	//po.setUpdateBy();
	//po.setUpdateDate();
	dao.insert(po);
	
	//TmDealerPriceRelationPO mypoFirst=new TmDealerPriceRelationPO();
	//mypoFirst.setDealerId(Long.parseLong(dealerId));
	//mypoFirst.setPriceId(Long.parseLong(userPrice));
	//TmDealerPriceRelationPO mypoEnd=new TmDealerPriceRelationPO();
	//mypoEnd.setIsDefault(Integer.parseInt(defaultPrice));
	//act.setOutData("defaultPrice",defaultPrice);
	//dao.update(mypoFirst,mypoEnd);
	act.setOutData("returnValue", 1);
}

	/*
	 * 添加经销商地址
	 */
	public void saveAddress() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		try {
			RequestWrapper request = act.getRequest();
			// CommonUtils.checkNull() 校验是否为空
			String dealerId = CommonUtils.checkNull(request
					.getParamValue("DEALER_ID"));// 经销商ID
			String addCode = CommonUtils.checkNull(request
					.getParamValue("ADD_CODE"));// 地址代码
			String address = CommonUtils.checkNull(request
					.getParamValue("ADDRESS"));// 地址名称
			String linkMan = CommonUtils.checkNull(request
					.getParamValue("linkMan"));// 联系人
			String status = CommonUtils.checkNull(request
					.getParamValue("ADDRESSSTATUS"));// 地址状态
			String tel = CommonUtils.checkNull(request.getParamValue("tel"));// 电话
			String remark = CommonUtils.checkNull(request
					.getParamValue("remark"));// 备注
			String proviceId = CommonUtils.checkNull(request
					.getParamValue("province"));// 获取省份
			String cityId = CommonUtils
					.checkNull(request.getParamValue("city"));// 获取城市
			String areaId = CommonUtils
					.checkNull(request.getParamValue("area"));// 获取县城
			String myaddress = CommonUtils.checkNull(request
					.getParamValue("myaddress"));// 获取收获单位
			// 从session中查询公司ID
			Date currTime = new Date(System.currentTimeMillis());
			Long userId = logonUser.getUserId();
			String id = SequenceManager.getSequence("");
			DealerInfoDao dao = new DealerInfoDao();
			TmVsAddressPO po = new TmVsAddressPO();
			if (proviceId != "") {
				po.setProvinceId(Long.parseLong(proviceId));
			}
			if (cityId != "") {
				po.setCityId(Long.parseLong(cityId));
			}
			if (areaId != "") {
				po.setAreaId(Long.parseLong(areaId));
			}
			po.setReceiveOrg(myaddress);
			po.setAddCode(addCode);
			po.setAddress(address);
			po.setCreateBy(userId);
			po.setCreateDate(currTime);
			po.setDealerId(Long.valueOf(dealerId));
			po.setId(Long.valueOf(id));
			po.setLinkMan(linkMan);
			po.setStatus(new Integer(status));
			po.setTel(tel);
			po.setRemark(remark);
			dao.insert(po);
			act.setOutData("returnValue", 1);

		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "经销商维护新增");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}

	/**
	 * 地址维护修改页面pre查询
	 * 
	 * @param null
	 * @return void
	 * @throws Exception
	 */
	public void modifyAdd() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		try {
			RequestWrapper request = act.getRequest();
			// CommonUtils.checkNull() 校验是否为空
			String dealerId = CommonUtils.checkNull(request
					.getParamValue("dealerId"));// 经销商ID
			String id = CommonUtils.checkNull(request.getParamValue("id"));// 地址ID
			DealerInfoDao dao = new DealerInfoDao();
			Map<String, Object> map = dao.getAddressfobyId(id);
			act.setOutData("dealerId", dealerId);
			act.setOutData("map", map);
			act.setForword(modifyAddressUrl);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "经销商维护新增");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}

	// 修改地址功能
	public void modifyAddressInfo() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);
		try {
			RequestWrapper request = act.getRequest();
			// CommonUtils.checkNull() 校验是否为空
			String dealerId = CommonUtils.checkNull(request
					.getParamValue("DEALER_ID"));// 经销商ID
			String addCode = CommonUtils.checkNull(request
					.getParamValue("ADD_CODE"));// 地址代码
			String address = CommonUtils.checkNull(request
					.getParamValue("ADDRESS"));// 地址名称
			String linkMan = CommonUtils.checkNull(request
					.getParamValue("linkMan"));// 联系人
			String status = CommonUtils.checkNull(request
					.getParamValue("ADDRESSSTATUS"));// 地址状态
			String tel = CommonUtils.checkNull(request.getParamValue("tel"));// 电话
			String remark = CommonUtils.checkNull(request
					.getParamValue("remark"));// 备注
			String id = CommonUtils.checkNull(request
					.getParamValue("ADDRESS_ID"));// 修改的地址ID
			String proviceId = CommonUtils.checkNull(request
					.getParamValue("province"));// 修改省份
			String cityId = CommonUtils
					.checkNull(request.getParamValue("city"));// 修改城市
			String areaId = CommonUtils
					.checkNull(request.getParamValue("area"));// 修改县城

			Date currTime = new Date(System.currentTimeMillis());
			Long userId = logonUser.getUserId();

			DealerInfoDao dao = new DealerInfoDao();
			TmVsAddressPO po = new TmVsAddressPO();
			TmVsAddressPO contionPo = new TmVsAddressPO();
			contionPo.setId(Long.valueOf(id));
			if (proviceId != "") {
				po.setProvinceId(Long.parseLong(proviceId));
			}
			if (cityId != "") {
				po.setCityId(Long.parseLong(cityId));
			}
			if (areaId != "") {
				po.setAreaId(Long.parseLong(areaId));
			}

			po.setReceiveOrg(request.getParamValue("myaddress"));// 收货单位
			po.setAddCode(addCode);
			po.setAddress(address);
			po.setUpdateBy(userId);
			po.setUpdateDate(currTime);
			po.setDealerId(Long.valueOf(dealerId));
			po.setLinkMan(linkMan);
			po.setStatus(new Integer(status));
			po.setTel(tel);
			po.setRemark(remark);
			dao.update(contionPo, po);
			act.setOutData("returnValue", 1);

		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "经销商维护新增");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}

	public void queryMonth(ActionContext act, DealerInfoDao dao,
			String dealerId, String url) throws Exception {
		// 查询插入信息
		Map<String, Object> map = dao.getDealerInfobyId(dealerId);
		// 查询经销商业务范围信息
		List<Map<String, Object>> businessList = dao
				.getDealerBusinessArea(dealerId);
		// 查询经销商地址信息
		List<Map<String, Object>> addressList = dao.getAddress(dealerId);
		act.setOutData("businessList", businessList);
		act.setOutData("addressList", addressList);
		act.setOutData("map", map);
		act.setForword(url);
	}
	
	public void chkDlr() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);
		
		try {
			RequestWrapper request = act.getRequest() ;
			
			String dlrId = request.getParamValue("dlrId") ;
			String dlrCode = request.getParamValue("dlrCode") ;
			
			if (null == dlrCode || "".equals(dlrCode)) {
				return ;
			}
			int errInfo = 0 ;	
			
			TmDealerPO tmd = new TmDealerPO() ;
			
			
			/* 
			 */
			if (null != dlrId && !"".equals(dlrId)) {
				TmDealerPO tmd_A = new TmDealerPO() ;
				tmd_A.setDealerId(Long.parseLong(dlrId)) ;
				
				TmDealerPO tmdA = (TmDealerPO)DealerInfoDao.getInstance().select(tmd_A).get(0) ;
				String Code = tmdA.getDealerCode() ;
				
				if (null != Code && Code.equals(dlrCode)) {
					return ;
				}
			}
			
			
			tmd.setDealerCode(dlrCode) ;
			
			
			
			long len = DealerInfoDao.getInstance().select(tmd).size() ;
			
			if(len >= 1) {
				errInfo = 1 ;
			}
			
			act.setOutData("errInfo", errInfo) ;
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "经销商维护修改操作");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	
	public void chkDealer() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);
		
		try {
			RequestWrapper request = act.getRequest() ;
			
			int errInfo = 0 ;	// 错误信息：0表示正常，1表示dealerId不存在，2表示当前经销商下维护有下级经销商
			String dealerId = request.getParamValue("dealerId") ;   // 获取经销商id
			String flag = request.getParamValue("flag") ;			// 获取操作空间标识
			
			if(null == dealerId || "".equals(dealerId)) {
				errInfo = 1 ;
			} else {
				TmDealerPO tmd = new TmDealerPO() ;
				tmd.setParentDealerD(Long.parseLong(dealerId)) ;
				tmd.setStatus(Constant.STATUS_ENABLE) ;
				
				long len = DealerInfoDao.getInstance().select(tmd).size() ;		// 获取所属当前经销商的下级经销商记录条数
				
				if(len > 0) {
					errInfo = 2 ;
				} else {
					errInfo = 0 ;
				}
			}
			
			act.setOutData("flag", flag) ;
			act.setOutData("errInfo", errInfo) ;
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "经销商维护修改操作");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	/****add by liuxh 201116 增加经销商代码重复判断*****/
	public void checkDealerCode(){
		String msg="true";
		POFactory factory = POFactoryBuilder.getInstance();
		ActionContext act = ActionContext.getContext();
		RequestWrapper request = act.getRequest() ;
		String dealerCode=CommonUtils.checkNull(request.getParamValue("DEALER_CODE"));//经销商代码 
		//String falg=CommonUtils.checkNull(request.getParamValue("OPER_FALG")); //操作标志
		TmDealerPO dealer=new TmDealerPO();
		dealer.setDealerCode(dealerCode);
		List listDlr=factory.select(dealer);
		if(listDlr.size()>0){
			msg="false";
		}
		act.setOutData("msg", msg);
	}
	/*
	 * 经销商结算暂停
	 */
	public void banlanceStop(){
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			act.setForword(BALANCE_STOP_URL);
		} catch (Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"经销商结算暂停");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	public void queryDealerBS(){
		ActionContext act = ActionContext.getContext();
		RequestWrapper req = act.getRequest() ;
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			String code = req.getParamValue("DEALER_CODE");
			String name = req.getParamValue("DEALER_NAME");
			String status = req.getParamValue("STATUS");
			StringBuffer sql = new StringBuffer();
			if(StringUtil.notNull(code))
				sql.append(" and d.dealer_code like '%").append(code).append("%'\n");
			if(StringUtil.notNull(name))
				sql.append(" and d.dealer_name like '%").append(name).append("%'\n");
			if(StringUtil.notNull(status))
				sql.append(" and t.status=").append(status).append("\n");
			DealerInfoDao dao=new DealerInfoDao();
			int pageSize = 15;
			Integer curPage = req.getParamValue("curPage")!=null?Integer.parseInt(req.getParamValue("curPage")):1;
			PageResult<Map<String,Object>> ps = dao.getDealerBS(sql.toString(),pageSize, curPage);
			
			act.setOutData("ps", ps);
		} catch (Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"经销商结算暂停");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	public void goUpdateBS(){
		ActionContext act = ActionContext.getContext();
		RequestWrapper req = act.getRequest() ;
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			String id = req.getParamValue("id");
			String con = " and d.dealer_id="+id ;
			DealerInfoDao dao=new DealerInfoDao();
			PageResult<Map<String,Object>> ps = dao.getDealerBS(con,2,1);
			if(ps.getTotalRecords()>0){
				if(ps.getRecords().size()>0)
					act.setOutData("map",ps.getRecords().get(0));
			}
			act.setForword(BALANCE_STOP_UPDATE);
		} catch (Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"经销商结算暂停");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	public void dealerBSUpdate(){
		ActionContext act = ActionContext.getContext();
		RequestWrapper req = act.getRequest() ;
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			String id = req.getParamValue("DEALER_ID");
			String status = req.getParamValue("STATUS");
			TtAsDealerTypePO dealer = new TtAsDealerTypePO() ;
			TtAsDealerTypePO dealer2 = new TtAsDealerTypePO() ;
			dealer.setDealerId(Long.parseLong(id));
			dealer.setStatus(status);
			dealer.setUpdateBy(logonUser.getUserId().toString());
			dealer.setUpdateDate(new Date());
			
			DealerInfoDao dao=new DealerInfoDao();
			dao.update(dealer2, dealer);
			act.setForword(BALANCE_STOP_URL);
		} catch (Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"经销商结算暂停");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	//zhumingwei add by 2011-02-24
	public void dealerInfoChangeInit(){
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			act.setForword(dealerInfoChangeInitUrl);
		} catch (Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	
	public void authDealerChangeInit(){
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			act.setForword(authDealerChangeInitUrl);
		} catch (Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	public void queryAuthDealerChange(){
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			RequestWrapper request = act.getRequest();
			String code = request.getParamValue("code");
			String status = request.getParamValue("status");
			String startDate = request.getParamValue("startDate");
			String endDate = request.getParamValue("endDate");
			if(Utility.testString(startDate))
				startDate = startDate + " 00:00:00";
			if(Utility.testString(endDate))
				endDate = endDate + " 23:59:59";
			DealerInfoDao dao=new DealerInfoDao();
			Integer curPage = request.getParamValue("curPage") != null ? Integer.parseInt(request.getParamValue("curPage"))
					: 1; // 处理当前页
					//Constant.PAGE_SIZE, curPage
			PageResult<Map<String, Object>> ps = dao.queryAuthDealerChange(code,status, startDate,endDate,curPage,Constant.PAGE_SIZE);  
			act.setOutData("ps", ps);
		} catch (Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	//zhumingwei add by 2011-02-24
	public void queryDealerInfoChange(){
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			RequestWrapper request = act.getRequest();
			String code = request.getParamValue("code");
			String status = request.getParamValue("status");
			String dealerId=logonUser.getDealerId();
			String startDate = request.getParamValue("startDate");
			String endDate = request.getParamValue("endDate");
			if(Utility.testString(startDate))
				startDate = startDate + " 00:00:00";
			if(Utility.testString(endDate))
				endDate = endDate + " 23:59:59";
			DealerInfoDao dao=new DealerInfoDao();
			Integer curPage = request.getParamValue("curPage") != null ? Integer.parseInt(request.getParamValue("curPage"))
					: 1; // 处理当前页
					//Constant.PAGE_SIZE, curPage
			PageResult<Map<String, Object>> ps = dao.queryDealerInfoChange(dealerId,code,status, startDate,endDate,curPage,Constant.PAGE_SIZE);  
			act.setOutData("ps", ps);
		} catch (Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	public void addDealerInfo(){
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			String dealer_id=logonUser.getDealerId();
			DealerInfoDao dao=new DealerInfoDao();
			List<Map<String, Object>> list = dao.selectDealerInfo(Long.parseLong(dealer_id));
			String dealerNum=SequenceManager.getSequence("BG");
			Date time = new Date();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			String time1=  sdf.format(time);
			act.setOutData("time1", time1);
			act.setOutData("list", list.get(0));
			act.setOutData("dealerNum", dealerNum);
			int DEALER_LEVEL_02 = Constant.DEALER_LEVEL_02;
			act.setOutData("DEALER_LEVEL_02", DEALER_LEVEL_02);
			act.setForword(addDealerInfoChangeUrl);
		} catch (Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	//zhumingwei add by 2011-02-25
	public void saveDealerChangeInfo(){
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			RequestWrapper request = act.getRequest();
			//CommonUtils.checkNull() 校验是否为空
			String dealerId = CommonUtils.checkNull(request.getParamValue("dealerId"));//原本经销商ID
			String dealerNum = CommonUtils.checkNull(request.getParamValue("dealerNum"));//单据编号
			String dealerCode = CommonUtils.checkNull(request.getParamValue("dealerCode"));//经销商代码
			String dealerName = CommonUtils.checkNull(request.getParamValue("dealerName"));//经销商名称
			String dealerType = CommonUtils.checkNull(request.getParamValue("dealerType"));//经销商类别
			Date changeDate = new Date();//变更时间
			String rootOrgCode = CommonUtils.checkNull(request.getParamValue("rootOrgCode"));//上级组织(备份)
			//String orgCode = CommonUtils.checkNull(request.getParamValue("orgCode"));//上级组织
			String orgId = CommonUtils.checkNull(request.getParamValue("orgId"));//上级组织
			String dealerClass = CommonUtils.checkNull(request.getParamValue("dealerClass"));//经销商类型(备份)
			String DEALERCLASS = CommonUtils.checkNull(request.getParamValue("DEALERCLASS"));//经销商类型
			String companyShortName = CommonUtils.checkNull(request.getParamValue("companyShortName"));//经销商公司(备份)
			//String COMPANY_NAME = CommonUtils.checkNull(request.getParamValue("COMPANY_NAME"));//经销商公司
			String COMPANY_ID = CommonUtils.checkNull(request.getParamValue("COMPANY_ID"));//经销商公司
			String province = CommonUtils.checkNull(request.getParamValue("province"));//省份(备份)
			String province1 = CommonUtils.checkNull(request.getParamValue("province1"));//省份
			String city = CommonUtils.checkNull(request.getParamValue("city"));//地级市(备份)
			String city1 = CommonUtils.checkNull(request.getParamValue("city1"));//地级市
			String COUNTIES = CommonUtils.checkNull(request.getParamValue("COUNTIES"));//区/县(备份)
			String COUNTIES1 = CommonUtils.checkNull(request.getParamValue("COUNTIES1"));//区/县
			String township = CommonUtils.checkNull(request.getParamValue("township"));//乡(备份)
			String TOWNSHIP = CommonUtils.checkNull(request.getParamValue("TOWNSHIP"));//乡
			String erpCode = CommonUtils.checkNull(request.getParamValue("erpCode"));//开票单位(备份)
			String erpCode1 = CommonUtils.checkNull(request.getParamValue("erpCode1"));//开票单位
			String address = CommonUtils.checkNull(request.getParamValue("address"));//详细地址(备份)
			String address1=CommonUtils.checkNull(request.getParamValue("address1"));//详细地址
			String remark = CommonUtils.checkNull(request.getParamValue("remark"));//备注(备份)
			String remark1=CommonUtils.checkNull(request.getParamValue("remark1"));//备注
			String imageLevel = CommonUtils.checkNull(request.getParamValue("imageLevel"));//形象等级(备份)
			String IMAGE_LEVEL = CommonUtils.checkNull(request.getParamValue("IMAGE_LEVEL"));//形象等级
			String dealerLevel = CommonUtils.checkNull(request.getParamValue("dealerLevel"));//经销商等级(备份)
			String DEALER_LEVEL = CommonUtils.checkNull(request.getParamValue("DEALER_LEVEL"));//经销商等级
			String parentName = CommonUtils.checkNull(request.getParamValue("parentName"));//上级经销商(备份)
			//String sJDealerCode = CommonUtils.checkNull(request.getParamValue("sJDealerCode"));//上级经销商
			String sJDealerId = CommonUtils.checkNull(request.getParamValue("sJDealerId"));//上级经销商
			String zipCode = CommonUtils.checkNull(request.getParamValue("zipCode"));//邮编(备份)
			String zipCode1 = CommonUtils.checkNull(request.getParamValue("zipCode1"));//邮编
			String legal = CommonUtils.checkNull(request.getParamValue("legal"));//法人(备份)
			String LEGAL = CommonUtils.checkNull(request.getParamValue("LEGAL"));//法人
			String personCharge = CommonUtils.checkNull(request.getParamValue("personCharge"));//负责人(备份)
			String personCharge1 = CommonUtils.checkNull(request.getParamValue("personCharge1"));//负责人
			String webmasterPhone = CommonUtils.checkNull(request.getParamValue("webmasterPhone"));//站长电话(备份)
			String WEBMASTER_PHONE = CommonUtils.checkNull(request.getParamValue("WEBMASTER_PHONE"));//站长电话
			String dutyPhone = CommonUtils.checkNull(request.getParamValue("dutyPhone"));//值班电话(备份)
			String DUTY_PHONE = CommonUtils.checkNull(request.getParamValue("DUTY_PHONE"));//值班电话
			String phone = CommonUtils.checkNull(request.getParamValue("phone"));//电话(备份)
			String phone1 = CommonUtils.checkNull(request.getParamValue("phone1"));//电话
			String faxNo = CommonUtils.checkNull(request.getParamValue("faxNo"));//传真(备份)
			String faxNo1 = CommonUtils.checkNull(request.getParamValue("faxNo1"));//传真
			String email = CommonUtils.checkNull(request.getParamValue("email"));//Email(备份)
			String email1 = CommonUtils.checkNull(request.getParamValue("email1"));//Email
			
			DealerInfoDao dao=new DealerInfoDao();//实例化
			
			TmDealerChangePO po = new TmDealerChangePO();
			po.setDealerChangeId(Long.parseLong(SequenceManager.getSequence("")));
			po.setDealerId(Long.parseLong(dealerId));
			po.setDealerNum(dealerNum);
			po.setDealerCode(dealerCode);
			po.setDealerName(dealerName);
			po.setDealerCategory(Long.parseLong(dealerType));
			po.setDealerTime(changeDate);
			po.setDealerLevelBck(Long.parseLong(dealerLevel));
			if(!"".equals(DEALER_LEVEL)){
				po.setDealerLevel(Long.parseLong(DEALER_LEVEL));
			}
			if(!"".equals(parentName)){
				po.setDealerHigherBck(parentName);
			}
			if(!"".equals(sJDealerId)){
				po.setDealerHigher(sJDealerId);
			}
			po.setZipCodeBck(zipCode);
			po.setZipCode(zipCode1);
			po.setLegalBck(legal);
			po.setLegal(LEGAL);
			po.setPersonChargeBck(personCharge);
			po.setPersonCharge(personCharge1);
			po.setWebmasterPhoneBck(webmasterPhone);
			po.setWebmasterPhone(WEBMASTER_PHONE);
			po.setDutyPhoneBck(dutyPhone);
			po.setDutyPhone(DUTY_PHONE);
			po.setPhoneBck(phone);
			po.setPhone(phone1);
			po.setFaxBck(faxNo);
			po.setFax(faxNo1);
			po.setEmailBck(email);
			po.setEmail(email1);
			
			po.setDealerHigherOrgBck(rootOrgCode);
			po.setDealerHigherOrg(orgId);
			if(!"".equals(dealerClass)){
				po.setDealerTypeBck(Long.parseLong(dealerClass));
			}
			if(!"".equals(DEALERCLASS)){
				po.setDealerType(Long.parseLong(DEALERCLASS));
			}
			po.setDealerCompanyBck(companyShortName);
			po.setDealerCompany(COMPANY_ID);
			po.setDealerProvincesBck(Long.parseLong(province));
			if(!"".equals(province1)){
				po.setDealerProvinces(Long.parseLong(province1));
			}
			if(!"".equals(city)){
				po.setDealerCityBck(Long.parseLong(city));
			}
			if(!"".equals(city1)){
				po.setDealerCity(Long.parseLong(city1));
			}
			if(!"".equals(COUNTIES)){
				po.setCountiesBck(Long.parseLong(COUNTIES));
			}
			if(!"".equals(COUNTIES1)){
				po.setCounties(Long.parseLong(COUNTIES1));
			}
			po.setTownshipBck(township);
			po.setTownship(TOWNSHIP);
			po.setBillingUnitBck(erpCode);
			po.setBillingUnit(erpCode1);
			po.setDetailsAddressBck(address);
			po.setDetailsAddress(address1);
			po.setDealerRemakeBck(remark);
			po.setDealerRemake(remark1);
			if(!"".equals(imageLevel)){
				po.setImageLevelBck(Long.parseLong(imageLevel));
			}
			if(!"".equals(IMAGE_LEVEL)){
				po.setImageLevel(Long.parseLong(IMAGE_LEVEL));
			}
			
			if(!"".equals(orgId) || !"".equals(DEALERCLASS) || !"".equals(COMPANY_ID) || !"".equals(province1) || !"".equals(city1) || !"".equals(COUNTIES1) || !"".equals(TOWNSHIP) || !"".equals(erpCode1) || !"".equals(address1) || !"".equals(remark1) || !"".equals(IMAGE_LEVEL)){
				po.setStatus(Long.parseLong(Constant.DEALER_CHANGE_01.toString()));
			}else{
				po.setStatus(Long.parseLong(Constant.DEALER_CHANGE_03.toString()));
				//如果不需要审核的，那么直接更新经销商表的数据
				TmDealerPO dealerPo = new TmDealerPO();
				dealerPo.setDealerId(Long.parseLong(dealerId));
				TmDealerPO dealerPoValue = new TmDealerPO();
				if(!"".equals(DEALER_LEVEL)){
					dealerPoValue.setDealerLevel(Integer.parseInt(DEALER_LEVEL));//经销商等级
				}
				if(!"".equals(sJDealerId)){
					dealerPoValue.setParentDealerD(Long.parseLong(sJDealerId));//上级经销商
				}
				if(!"".equals(zipCode1)){
					dealerPoValue.setZipCode(zipCode1);
				}
				if(!"".equals(LEGAL)){
					dealerPoValue.setLegal(LEGAL);
				}
				if(!"".equals(personCharge1)){
					dealerPoValue.setPersonCharge(personCharge1);
				}
				if(!"".equals(WEBMASTER_PHONE)){
					dealerPoValue.setWebmasterPhone(WEBMASTER_PHONE);
				}
				if(!"".equals(DUTY_PHONE)){
					dealerPoValue.setDutyPhone(DUTY_PHONE);
				}
				if(!"".equals(phone1)){
					dealerPoValue.setPhone(phone1);
				}
				if(!"".equals(faxNo1)){
					dealerPoValue.setFaxNo(faxNo1);
				}
				if(!"".equals(email1)){
					dealerPoValue.setEmail(email1);
				}
				dao.update(dealerPo,dealerPoValue);
			}
			po.setCreateBy(logonUser.getUserId());
			po.setCreateDate(new Date());
			
			//附近功能：
			String[] fjids = request.getParamValues("fjid");
			FileUploadManager.fileUploadByBusiness(po.getDealerChangeId().toString(), fjids, logonUser);	
			
			dao.insert(po);
			act.setForword(dealerInfoChangeInitUrl);
		} catch (Exception e) {
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"经销商变更新增");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	public void dealerDetailInfo(){
		ActionContext act = ActionContext.getContext();
		//AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		RequestWrapper request = act.getRequest();
		//CommonUtils.checkNull() 校验是否为空
		String id = CommonUtils.checkNull(request.getParamValue("id"));
		DealerInfoDao dao=new DealerInfoDao();//实例化
		TmDealerChangePO po = new TmDealerChangePO();
		po.setDealerChangeId(Long.parseLong(id));
		TmDealerChangePO poValue = (TmDealerChangePO)dao.select(po).get(0);
		act.setOutData("poValue", poValue);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String time = sdf.format(poValue.getDealerTime());
		act.setOutData("time", time);
		StandardVipApplyManagerDao smDao = new StandardVipApplyManagerDao();
		List<FsFileuploadPO> fileList= smDao.queryAttachFileInfo(id);
		act.setOutData("fileList", fileList);
		
		if(!"".equals(CommonUtils.checkNull(poValue.getDealerHigherOrg()))){
			TmOrgPO popo = new TmOrgPO();
			popo.setOrgId(Long.parseLong(poValue.getDealerHigherOrg()));
			TmOrgPO popoValue = (TmOrgPO)dao.select(popo).get(0);
			act.setOutData("orgCode", popoValue.getOrgCode());
		}
		
		if(!"".equals(CommonUtils.checkNull(poValue.getDealerCompany()))){
			TmCompanyPO popopo = new TmCompanyPO();
			popopo.setCompanyId(Long.parseLong(poValue.getDealerCompany()));
			TmCompanyPO popopoValue = (TmCompanyPO)dao.select(popopo).get(0);
			String companyName = popopoValue.getCompanyShortname();
			act.setOutData("companyName", companyName);
		}
		
		act.setForword(dealerDetailInfo);
	}
	
	public void authInfo(){
		ActionContext act = ActionContext.getContext();
		RequestWrapper request = act.getRequest();
		//CommonUtils.checkNull() 校验是否为空
		String id = CommonUtils.checkNull(request.getParamValue("id"));
		DealerInfoDao dao=new DealerInfoDao();//实例化
		TmDealerChangePO po = new TmDealerChangePO();
		po.setDealerChangeId(Long.parseLong(id));
		TmDealerChangePO poValue = (TmDealerChangePO)dao.select(po).get(0);
		act.setOutData("poValue", poValue);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String time = sdf.format(poValue.getDealerTime());
		act.setOutData("time", time);
		StandardVipApplyManagerDao smDao = new StandardVipApplyManagerDao();
		List<FsFileuploadPO> fileList= smDao.queryAttachFileInfo(id);
		act.setOutData("fileList", fileList);
		act.setOutData("ID", id);
		
		if(!"".equals(CommonUtils.checkNull(poValue.getDealerHigherOrg()))){
			TmOrgPO popo = new TmOrgPO();
			popo.setOrgId(Long.parseLong(poValue.getDealerHigherOrg()));
			TmOrgPO popoValue = (TmOrgPO)dao.select(popo).get(0);
			act.setOutData("orgCode", popoValue.getOrgCode());
		}
		
		if(!"".equals(CommonUtils.checkNull(poValue.getDealerCompany()))){
			TmCompanyPO popopo = new TmCompanyPO();
			popopo.setCompanyId(Long.parseLong(poValue.getDealerCompany()));
			TmCompanyPO popopoValue = (TmCompanyPO)dao.select(popopo).get(0);
			String companyName = popopoValue.getCompanyShortname();
			act.setOutData("companyName", companyName);
		}
		if(!"".equals(CommonUtils.checkNull(poValue.getDealerHigher()))){
			TmDealerPO popopopo = new TmDealerPO();
			popopopo.setDealerId(Long.parseLong(poValue.getDealerHigher()));
			TmDealerPO popopopoValue = (TmDealerPO)dao.select(popopopo).get(0);
			String dealerName = popopopoValue.getDealerShortname();
			act.setOutData("dealerName", dealerName);
		}
		
		act.setForword(authDetailInfo);
	}
	
	public void  updateDealerDetailInfo(){
		ActionContext act = ActionContext.getContext();
		//AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		RequestWrapper request = act.getRequest();
		String id = CommonUtils.checkNull(request.getParamValue("id"));
		DealerInfoDao dao=new DealerInfoDao();//实例化
		TmDealerChangePO po = new TmDealerChangePO();
		po.setDealerChangeId(Long.parseLong(id));
		TmDealerChangePO poValue = (TmDealerChangePO)dao.select(po).get(0);
		act.setOutData("poValue", poValue);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String time = sdf.format(poValue.getDealerTime());
		act.setOutData("time", time);
		act.setOutData("dealerChangeId", id);
		StandardVipApplyManagerDao smDao = new StandardVipApplyManagerDao();
		List<FsFileuploadPO> fileList= smDao.queryAttachFileInfo(id);
		act.setOutData("fileList", fileList);
		
		//得到上级组织代码
		if(!"".equals(CommonUtils.checkNull(poValue.getDealerHigherOrg()))){
			TmOrgPO popo = new TmOrgPO();
			popo.setOrgId(Long.parseLong(poValue.getDealerHigherOrg()));
			TmOrgPO popoValue = (TmOrgPO)dao.select(popo).get(0);
			String orgCode = popoValue.getOrgCode();
			act.setOutData("dealerHigherOrgId", poValue.getDealerHigherOrg());
			act.setOutData("orgCode", orgCode);
		}
		if(!"".equals(CommonUtils.checkNull(poValue.getDealerCompany()))){
			TmCompanyPO popopo = new TmCompanyPO();
			popopo.setCompanyId(Long.parseLong(poValue.getDealerCompany()));
			TmCompanyPO popopoValue = (TmCompanyPO)dao.select(popopo).get(0);
			String companyName = popopoValue.getCompanyShortname();
			act.setOutData("companyName", companyName);
			act.setOutData("companyId", poValue.getDealerCompany());
		}
		if(!"".equals(CommonUtils.checkNull(poValue.getDealerHigher()))){
			TmDealerPO popopopo = new TmDealerPO();
			popopopo.setDealerId(Long.parseLong(poValue.getDealerHigher()));
			TmDealerPO popopopoValue = (TmDealerPO)dao.select(popopopo).get(0);
			String dealerCode = popopopoValue.getDealerCode();
			act.setOutData("dealerCode", dealerCode);
			act.setOutData("dealerId", poValue.getDealerHigher());
		}
		
		act.setForword(updateDealerDetailInfo);
	}
	
	public void updateDealerChangeInfo(){
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		RequestWrapper request = act.getRequest();
		DealerInfoDao dao=new DealerInfoDao();//实例化
		String dealerChangeId = CommonUtils.checkNull(request.getParamValue("dealerChangeId"));
		//String orgCode = CommonUtils.checkNull(request.getParamValue("orgCode"));//上级组织
		String orgId = CommonUtils.checkNull(request.getParamValue("orgId"));//上级组织
		String DEALERCLASS = CommonUtils.checkNull(request.getParamValue("DEALERCLASS"));//经销商类型
		//String COMPANY_NAME = CommonUtils.checkNull(request.getParamValue("COMPANY_NAME"));//经销商公司
		String COMPANY_ID = CommonUtils.checkNull(request.getParamValue("COMPANY_ID"));//经销商公司
		String province1 = CommonUtils.checkNull(request.getParamValue("province1"));//省份
		String city1 = CommonUtils.checkNull(request.getParamValue("city1"));//地级市
		String COUNTIES1 = CommonUtils.checkNull(request.getParamValue("COUNTIES1"));//区/县
		String TOWNSHIP = CommonUtils.checkNull(request.getParamValue("TOWNSHIP"));//乡
		String erpCode1 = CommonUtils.checkNull(request.getParamValue("erpCode1"));//开票单位
		String address1=CommonUtils.checkNull(request.getParamValue("address1"));//详细地址
		String remark1=CommonUtils.checkNull(request.getParamValue("remark1"));//备注
		String IMAGE_LEVEL = CommonUtils.checkNull(request.getParamValue("IMAGE_LEVEL"));//形象等级
		String DEALER_LEVEL = CommonUtils.checkNull(request.getParamValue("DEALER_LEVEL"));//经销商等级
		//String sJDealerCode = CommonUtils.checkNull(request.getParamValue("sJDealerCode"));//上级经销商
		String sJDealerId = CommonUtils.checkNull(request.getParamValue("sJDealerId"));//上级经销商
		String zipCode1 = CommonUtils.checkNull(request.getParamValue("zipCode1"));//邮编
		String LEGAL = CommonUtils.checkNull(request.getParamValue("LEGAL"));//法人
		String personCharge1 = CommonUtils.checkNull(request.getParamValue("personCharge1"));//负责人
		String WEBMASTER_PHONE = CommonUtils.checkNull(request.getParamValue("WEBMASTER_PHONE"));//站长电话
		String DUTY_PHONE = CommonUtils.checkNull(request.getParamValue("DUTY_PHONE"));//值班电话
		String phone1 = CommonUtils.checkNull(request.getParamValue("phone1"));//电话
		String faxNo1 = CommonUtils.checkNull(request.getParamValue("faxNo1"));//传真
		String email1 = CommonUtils.checkNull(request.getParamValue("email1"));//Email
		TmDealerChangePO po = new TmDealerChangePO();
		po.setDealerChangeId(Long.parseLong(dealerChangeId));
		TmDealerChangePO poValue = new TmDealerChangePO();
		
		if(!"".equals(DEALER_LEVEL)){
			poValue.setDealerLevel(Long.parseLong(DEALER_LEVEL));
		}
		if(!"".equals(sJDealerId)){
			poValue.setDealerHigher(sJDealerId);
		}
		poValue.setZipCode(zipCode1);
		poValue.setLegal(LEGAL);
		poValue.setPersonCharge(personCharge1);
		poValue.setWebmasterPhone(WEBMASTER_PHONE);
		poValue.setDutyPhone(DUTY_PHONE);
		poValue.setPhone(phone1);
		poValue.setFax(faxNo1);
		poValue.setEmail(email1);
		
		poValue.setDealerHigherOrg(orgId);
		if(!"".equals(DEALERCLASS)){
			poValue.setDealerType(Long.parseLong(DEALERCLASS));
		}
		poValue.setDealerCompany(COMPANY_ID);
		if(!"".equals(province1)){
			poValue.setDealerProvinces(Long.parseLong(province1));
		}
		if(!"".equals(city1)){
			poValue.setDealerCity(Long.parseLong(city1));
		}
		if(!"".equals(COUNTIES1)){
			poValue.setCounties(Long.parseLong(COUNTIES1));
		}
		poValue.setTownship(TOWNSHIP);
		poValue.setBillingUnit(erpCode1);
		poValue.setDetailsAddress(address1);
		poValue.setDealerRemake(remark1);
		if(!"".equals(IMAGE_LEVEL)){
			poValue.setImageLevel(Long.parseLong(IMAGE_LEVEL));
		}
		if(!"".equals(orgId) || !"".equals(DEALERCLASS) || !"".equals(COMPANY_ID) || !"".equals(province1) || !"".equals(city1) || !"".equals(COUNTIES1) || !"".equals(TOWNSHIP) || !"".equals(erpCode1) || !"".equals(address1) || !"".equals(remark1) || !"".equals(IMAGE_LEVEL)){
			poValue.setStatus(Long.parseLong(Constant.DEALER_CHANGE_01.toString()));
		}else{
			poValue.setStatus(Long.parseLong(Constant.DEALER_CHANGE_03.toString()));
		}
		poValue.setUpdateBy(logonUser.getUserId());
		poValue.setUpdateDate(new Date());
		
		try {
			//附近功能：
			String ywzj = dealerChangeId;
			String[] fjids = request.getParamValues("fjid");
			FileUploadManager.delAllFilesUploadByBusiness(ywzj,fjids);//删除附件
			FileUploadManager.fileUploadByBusiness(ywzj, fjids, logonUser);	//新添加附件
		} catch (SQLException e) {
			e.printStackTrace();
		}	
		
		dao.update(po,poValue);
		act.setForword(dealerInfoChangeInitUrl);
	}
	
	public void reported(){
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		RequestWrapper request = act.getRequest();
		DealerInfoDao dao=new DealerInfoDao();//实例化
		String id = CommonUtils.checkNull(request.getParamValue("id"));
		TmDealerChangePO po = new TmDealerChangePO();
		po.setDealerChangeId(Long.parseLong(id));
		TmDealerChangePO poValue = new TmDealerChangePO();
		poValue.setStatus(Long.parseLong(Constant.DEALER_CHANGE_02.toString()));
		int count = dao.update(po, poValue);
		if(count>0){
			TmAuthDealerChangePO authPo = new TmAuthDealerChangePO();
			authPo.setId(Long.parseLong(SequenceManager.getSequence("")));
			authPo.setAuthDealer(Long.parseLong(logonUser.getDealerId()));
			authPo.setAuthTime(new Date());
			authPo.setAuthBy(logonUser.getUserId());
			authPo.setAuthStatus(Long.parseLong(Constant.DEALER_CHANGE_02.toString()));
			authPo.setCreateBy(logonUser.getUserId());
			authPo.setCreateDate(new Date());
			dao.insert(authPo);
			act.setOutData("ACTION_RESULT", "1");
		}else{
			act.setOutData("ACTION_RESULT", "2");
		}
	}
	
	public void authDealerChange(){
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		RequestWrapper request = act.getRequest();
		DealerInfoDao dao=new DealerInfoDao();//实例化
		String dealerHigherOrg = CommonUtils.checkNull(request.getParamValue("dealerHigherOrg"));
		String dealerType = CommonUtils.checkNull(request.getParamValue("dealerType"));
		String companyId = CommonUtils.checkNull(request.getParamValue("companyId"));
		String dealerProvinces = CommonUtils.checkNull(request.getParamValue("dealerProvinces"));
		String dealerCity = CommonUtils.checkNull(request.getParamValue("dealerCity"));
		String counties = CommonUtils.checkNull(request.getParamValue("counties"));
		String township = CommonUtils.checkNull(request.getParamValue("township"));
		String billingUnit = CommonUtils.checkNull(request.getParamValue("billingUnit"));
		String detailsAddress = CommonUtils.checkNull(request.getParamValue("detailsAddress"));
		String dealerRemake = CommonUtils.checkNull(request.getParamValue("dealerRemake"));
		String imageLevel = CommonUtils.checkNull(request.getParamValue("imageLevel"));
		String dealerLevel = CommonUtils.checkNull(request.getParamValue("dealerLevel"));
		String dealerHigher = CommonUtils.checkNull(request.getParamValue("dealerHigher"));
		String zipCode = CommonUtils.checkNull(request.getParamValue("zipCode"));
		String legal = CommonUtils.checkNull(request.getParamValue("legal"));
		String personCharge = CommonUtils.checkNull(request.getParamValue("personCharge"));
		String webmasterPhone = CommonUtils.checkNull(request.getParamValue("webmasterPhone"));
		String dutyPhone = CommonUtils.checkNull(request.getParamValue("dutyPhone"));
		String phone = CommonUtils.checkNull(request.getParamValue("phone"));
		String fax = CommonUtils.checkNull(request.getParamValue("fax"));
		String email = CommonUtils.checkNull(request.getParamValue("email"));
		String info = CommonUtils.checkNull(request.getParamValue("info"));
		
		String ID = CommonUtils.checkNull(request.getParamValue("ID"));
		
		String dealerId = CommonUtils.checkNull(request.getParamValue("dealerId"));
		TmDealerPO po = new TmDealerPO();
		po.setDealerId(Long.parseLong(dealerId));
		TmDealerPO poValue = new TmDealerPO();
		if(!"0".equals(dealerHigherOrg) && !"".equals(dealerHigherOrg)){
			poValue.setDealerOrgId(Long.parseLong(dealerHigherOrg));
		}
		if(!"0".equals(dealerType) && !"".equals(dealerHigherOrg)){
			poValue.setDealerClass(Integer.parseInt(dealerType));
		}
		if(!"0".equals(companyId) && !"".equals(dealerHigherOrg)){
			poValue.setCompanyId(Long.parseLong(companyId));
		}
		if(!"0".equals(dealerProvinces) && !"".equals(dealerHigherOrg)){
			poValue.setProvinceId(Long.parseLong(dealerProvinces));
		}
		if(!"0".equals(dealerCity) && !"".equals(dealerHigherOrg)){
			poValue.setCityId(Long.parseLong(dealerCity));
		}
		if(!"0".equals(counties) && !"".equals(dealerHigherOrg)){
			poValue.setCounties(Integer.parseInt(counties));
		}
		if(!"0".equals(counties) && !"".equals(dealerHigherOrg)){
			poValue.setCounties(Integer.parseInt(counties));
		}
		if(!"".equals(township)){
			poValue.setTownship(township);
		}
		if(!"".equals(billingUnit)){
			poValue.setAddress(billingUnit);
		}
		if(!"".equals(detailsAddress)){
			poValue.setAddress(detailsAddress);
		}
		if(!"".equals(dealerRemake)){
			poValue.setRemark(dealerRemake);
		}
		if(!"0".equals(imageLevel) && !"".equals(dealerHigherOrg)){
			poValue.setImageLevel(Integer.parseInt(imageLevel));
		}
		if(!"0".equals(dealerLevel) && !"".equals(dealerHigherOrg)){
			poValue.setDealerLevel(Integer.parseInt(dealerLevel));
		}
		if(!"0".equals(dealerHigher) && !"".equals(dealerHigher)){
			poValue.setParentDealerD(Long.parseLong(dealerHigher));
		}
		if(!"".equals(zipCode)){
			poValue.setZipCode(zipCode);
		}
		if(!"".equals(legal)){
			poValue.setLegal(legal);
		}
		if(!"".equals(personCharge)){
			poValue.setPersonCharge(personCharge);
		}
		if(!"".equals(webmasterPhone)){
			poValue.setWebmasterPhone(webmasterPhone);
		}
		if(!"".equals(dutyPhone)){
			poValue.setDutyPhone(dutyPhone);
		}
		if(!"".equals(phone)){
			poValue.setPhone(phone);
		}
		if(!"".equals(fax)){
			poValue.setFaxNo(fax);
		}
		if(!"".equals(email)){
			poValue.setEmail(email);
		}
		int count = dao.update(po, poValue);
		if(count>0){
			TmDealerChangePO poChange = new TmDealerChangePO();
			poChange.setDealerChangeId(Long.parseLong(ID));
			TmDealerChangePO poChangeValue = new TmDealerChangePO();
			poChangeValue.setStatus(Long.parseLong(Constant.DEALER_CHANGE_03.toString()));
			poChangeValue.setAuthRemark(info);
			poChangeValue.setUpdateBy(logonUser.getUserId());
			poChangeValue.setUpdateDate(new Date());
			int count1 = dao.update(poChange, poChangeValue);
			if(count1>0){
				TmAuthDealerChangePO popo = new TmAuthDealerChangePO();
				popo.setId(Long.parseLong(SequenceManager.getSequence("")));
				popo.setAuthDealer(Long.parseLong(dealerId));
				popo.setAuthTime(new Date());
				popo.setAuthBy(logonUser.getUserId());
				popo.setAuthStatus(Long.parseLong(Constant.DEALER_CHANGE_03.toString()));
				popo.setAuthRemark(info);
				popo.setCreateBy(logonUser.getUserId());
				popo.setCreateDate(new Date());
				dao.insert(popo);
			}
			
			this.authDealerChangeInit();
		}
	}
	public void rejectDealerChange(){
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		RequestWrapper request = act.getRequest();
		DealerInfoDao dao=new DealerInfoDao();//实例化
		String ID = CommonUtils.checkNull(request.getParamValue("ID"));
		String dealerId = CommonUtils.checkNull(request.getParamValue("dealerId"));
		String info = CommonUtils.checkNull(request.getParamValue("info"));
		TmDealerChangePO po = new TmDealerChangePO();
		po.setDealerChangeId(Long.parseLong(ID));
		TmDealerChangePO poValue = new TmDealerChangePO();
		poValue.setStatus(Long.parseLong(Constant.DEALER_CHANGE_04.toString()));
		poValue.setUpdateBy(logonUser.getUserId());
		poValue.setUpdateDate(new Date());
		poValue.setAuthRemark(info);
		int count = dao.update(po, poValue);
		if(count>0){
			TmAuthDealerChangePO popo = new TmAuthDealerChangePO();
			popo.setId(Long.parseLong(SequenceManager.getSequence("")));
			popo.setAuthDealer(Long.parseLong(dealerId));
			popo.setAuthTime(new Date());
			popo.setAuthBy(logonUser.getUserId());
			popo.setAuthStatus(Long.parseLong(Constant.DEALER_CHANGE_04.toString()));
			popo.setAuthRemark(info);
			popo.setCreateBy(logonUser.getUserId());
			popo.setCreateDate(new Date());
			dao.insert(popo);
			
			this.authDealerChangeInit();
		}
	}
	
	public void dealerInfo(){
		ActionContext act = ActionContext.getContext();
		RequestWrapper request = act.getRequest();
		//CommonUtils.checkNull() 校验是否为空
		String id = CommonUtils.checkNull(request.getParamValue("id"));
		DealerInfoDao dao=new DealerInfoDao();//实例化
		TmDealerChangePO po = new TmDealerChangePO();
		po.setDealerChangeId(Long.parseLong(id));
		TmDealerChangePO poValue = (TmDealerChangePO)dao.select(po).get(0);
		act.setOutData("poValue", poValue);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String time = sdf.format(poValue.getDealerTime());
		act.setOutData("time", time);
		StandardVipApplyManagerDao smDao = new StandardVipApplyManagerDao();
		List<FsFileuploadPO> fileList= smDao.queryAttachFileInfo(id);
		act.setOutData("fileList", fileList);
		act.setOutData("ID", id);
		
		//得到上级组织代码
		if(!"".equals(CommonUtils.checkNull(poValue.getDealerHigherOrg()))){
			TmOrgPO popo = new TmOrgPO();
			popo.setOrgId(Long.parseLong(poValue.getDealerHigherOrg()));
			TmOrgPO popoValue = (TmOrgPO)dao.select(popo).get(0);
			String orgCode = popoValue.getOrgCode();
			act.setOutData("dealerHigherOrgId", poValue.getDealerHigherOrg());
			act.setOutData("orgCode", orgCode);
		}
		if(!"".equals(CommonUtils.checkNull(poValue.getDealerCompany()))){
			TmCompanyPO popopo = new TmCompanyPO();
			popopo.setCompanyId(Long.parseLong(poValue.getDealerCompany()));
			TmCompanyPO popopoValue = (TmCompanyPO)dao.select(popopo).get(0);
			String companyName = popopoValue.getCompanyShortname();
			act.setOutData("companyName", companyName);
			act.setOutData("companyId", poValue.getDealerCompany());
		}
		if(!"".equals(CommonUtils.checkNull(poValue.getDealerHigher()))){
			TmDealerPO popopopo = new TmDealerPO();
			popopopo.setDealerId(Long.parseLong(poValue.getDealerHigher()));
			TmDealerPO popopopoValue = (TmDealerPO)dao.select(popopopo).get(0);
			String dealerName = popopopoValue.getDealerShortname();
			act.setOutData("dealerName", dealerName);
		}
		
		act.setForword(dealerChangeInfo);
	}
}